﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using WebChatApi.Common;

namespace WebChatApi.Common.Calendar
{
    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    public class CalendarWeek
    {
        #region Properties

        /// <summary>
        /// Gets or sets the date time.
        /// </summary>
        /// <value>
        /// The date time.
        /// </value>
        [DataMember]
        public DateTime StartDay
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the days.
        /// </summary>
        /// <value>
        /// The days.
        /// </value>
        [DataMember]
        public List<CalendarDay> Days
        {
            get;
            set;
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarWeek"/> class.
        /// </summary>
        public CalendarWeek()
            : this(DayOfWeek.Sunday)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarWeek"/> class.
        /// </summary>
        /// <param name="firstDayOfWeek">The first day of week.</param>
        public CalendarWeek(DayOfWeek firstDayOfWeek)
            : this(DateTime.Now, firstDayOfWeek)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarWeek" /> class.
        /// </summary>
        /// <param name="referenceDay">The reference day.</param>
        /// <param name="firstDayOfWeek">The first day of week.</param>
        public CalendarWeek(DateTime referenceDay, DayOfWeek firstDayOfWeek)
        {
            this.Days = new List<CalendarDay>();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarWeek" /> class.
        /// </summary>
        /// <param name="startDay">The start day.</param>
        public CalendarWeek(DateTime startDay)
            : this(startDay, startDay.DayOfWeek)
        {
        }

        #endregion

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return ToString(CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="cultureInfo">The culture info.</param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public string ToString(CultureInfo cultureInfo)
        {
            return this.StartDay.ToString(CommonExtensions.westenDateFormat, cultureInfo) + " - " + this.StartDay.AddDays(7).ToString(CommonExtensions.westenDateFormat, cultureInfo);
        }
    }
}
